/*
 * Copyright 2008-2009 Daniel Cachapa <cachapa@gmail.com>
 * 
 * This program is distributed under the terms of the GNU General Public Licence Version 3
 * The licence can be read in its entirety in the LICENSE.txt file accompaning this source code,
 * or at: http://www.gnu.org/copyleft/gpl.html
 * 
 * This file is part of WeightWatch.
 *
 * WeightWatch is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * WeightWatch is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the WeightWatch source code. If not, see
 * <http://www.gnu.org/licenses/>.
 */

package net.cachapa.weightwatch.ui;

import com.sun.lwuit.Button;
import com.sun.lwuit.Container;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import net.cachapa.weightwatch.util.L;

public class AboutContainer extends Container implements PreferencesContainer, ActionListener {
	private Application application;
	private String name;
	private Image icon;
	private Button updateButton;

	public AboutContainer(Application application) {
		this.application = application;
		this.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
		this.setScrollableY(true);
		this.name = L.l("pref_tab_about");
		try {
			this.icon = Image.createImage("/icon.png");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
		Label applicationLabel = new Label();
		applicationLabel.setAlignment(CENTER);
		applicationLabel.setText("WeightWatch v" + application.getAppProperty("MIDlet-Version"));
		this.addComponent(applicationLabel);
		
		Label aboutLabel = new Label("about_description");
		aboutLabel.setAlignment(CENTER);
		this.addComponent(aboutLabel);
		
		Label urlLabel = new Label("http://code.google.com/p/weightwatch");
		urlLabel.setAlignment(CENTER);
		urlLabel.setFocusable(true);
		this.addComponent(urlLabel);
		
		Label emailLabel = new Label("cachapa@gmail.com");
		emailLabel.setAlignment(CENTER);
		this.addComponent(emailLabel);
		
		updateButton = new Button("about_update");
		updateButton.setAlignment(CENTER);
		updateButton.addActionListener(this);
		this.addComponent(updateButton);
	}

	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == updateButton) {
			application.performAction(Application.SHOW_UPDATE_FORM);
		}
	}

	public String getName() {
		return name;
	}

	public Image getIcon() {
		return icon;
	}
}
